package com.brainhealth.web.controller.customer;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.annotation.RepeatSubmit;
import com.brainhealth.customer.domain.Learn;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.brainhealth.common.annotation.Log;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.enums.BusinessType;
import com.brainhealth.customer.domain.CustomerCollect;
import com.brainhealth.customer.service.ICustomerCollectService;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.common.core.page.TableDataInfo;

/**
 * 会员收藏Controller
 * 
 * @author wolong
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/customer/customerCollect")
public class CustomerCollectController extends BaseController
{
    @Autowired
    private ICustomerCollectService customerCollectService;

    /**
     * 查询会员收藏列表
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerCollect customerCollect)
    {
        startPage();
        List<CustomerCollect> list = customerCollectService.selectCustomerCollectList(customerCollect);
        return getDataTable(list);
    }

    /**
     * 导出会员收藏列表
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:export')")
    @Log(title = "会员收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerCollect customerCollect)
    {
        List<CustomerCollect> list = customerCollectService.selectCustomerCollectList(customerCollect);
        ExcelUtil<CustomerCollect> util = new ExcelUtil<CustomerCollect>(CustomerCollect.class);
        util.exportExcel(response, list, "会员收藏数据");
    }

    /**
     * 获取会员收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:query')")
    @GetMapping(value = "/{customerCollectId}")
    public AjaxResult getInfo(@PathVariable("customerCollectId") Long customerCollectId)
    {
        return success(customerCollectService.selectCustomerCollectByCustomerCollectId(customerCollectId));
    }

    /**
     * 新增会员收藏
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:add')")
    @Log(title = "会员收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerCollect customerCollect)
    {
        return toAjax(customerCollectService.insertCustomerCollect(customerCollect));
    }

    /**
     * 修改会员收藏
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:edit')")
    @Log(title = "会员收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerCollect customerCollect)
    {
        return toAjax(customerCollectService.updateCustomerCollect(customerCollect));
    }

    /**
     * 删除会员收藏
     */
    @PreAuthorize("@ss.hasPermi('customer:customerCollect:remove')")
    @Log(title = "会员收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerCollectIds}")
    public AjaxResult remove(@PathVariable Long[] customerCollectIds)
    {
        return toAjax(customerCollectService.deleteCustomerCollectByCustomerCollectIds(customerCollectIds));
    }

    /**
     * 收藏和取消学习库内容
     * @param request
     * @param learn
     * @return
     */
    @Anonymous
    @RepeatSubmit
    @PostMapping("/collectLearn")
    public AjaxResult collectLearn(HttpServletRequest request, @RequestBody Learn learn)
    {
        boolean result = customerCollectService.collectLearn(request,learn);
        if (result)
        {
            return AjaxResult.success("收藏成功！");
        }
        return AjaxResult.error("取消收藏成功！");
    }

    /**
     * 获取会员收藏列表
     * @param request
     * @return
     */
    @Anonymous
    @PostMapping("/getCollectList")
    public AjaxResult getCollectList(HttpServletRequest request)
    {
        return AjaxResult.success(customerCollectService.getCollectList(request));
    }

}
